<?php

/**
 * This is the model class for table "v_page".
 *
 * The followings are the available columns in table 'v_page':
 * @property string $ID
 * @property string $page_author
 * @property string $page_date
 * @property string $page_content
 * @property string $page_title
 * @property string $page_status
 * @property string $comment_status
 * @property string $page_modified
 * @property string $page_parent
 * @property string $comment_count
 */
class Page extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'v_page';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('page_content, page_title', 'required'),
			array('page_author, page_status, comment_status, page_parent, comment_count', 'length', 'max'=>20),
			array('page_date, page_modified', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('ID, page_author, page_date, page_content, page_title, page_status, comment_status, page_modified, page_parent, comment_count', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID' => 'ID',
			'page_author' => 'Page Author',
			'page_date' => 'Page Date',
			'page_content' => 'Page Content',
			'page_title' => 'Page Title',
			'page_status' => 'Page Status',
			'comment_status' => 'Comment Status',
			'page_modified' => 'Page Modified',
			'page_parent' => 'Page Parent',
			'comment_count' => 'Comment Count',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID',$this->ID,true);
		$criteria->compare('page_author',$this->page_author,true);
		$criteria->compare('page_date',$this->page_date,true);
		$criteria->compare('page_content',$this->page_content,true);
		$criteria->compare('page_title',$this->page_title,true);
		$criteria->compare('page_status',$this->page_status,true);
		$criteria->compare('comment_status',$this->comment_status,true);
		$criteria->compare('page_modified',$this->page_modified,true);
		$criteria->compare('page_parent',$this->page_parent,true);
		$criteria->compare('comment_count',$this->comment_count,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function getPagecontent($name)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.
	
		$criteria=new CDbCriteria;
		$criteria->select = '*';
		$criteria->addCondition("page_title = '".$name."'");
	
		$models = Page::model()->findAll($criteria);
		
		
		return $models;
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Page the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
